import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, ScrollView, Image, Text } from "@tarojs/components-rn";
import { toJS } from 'mobx';
import { inject, observer } from "@tarojs/mobx-rn";
import { getRuntime, pageSize, getAvatar, subtime } from "../../utils/common";
import my_profit_listStyleSheet from "./my_profit_list_styles";

import lawyer_pic from "../../assets/img/icon_16.png";
import noce_record from "../../assets/img/none_cash.png";
var _styleSheet = my_profit_listStyleSheet;

function _getClassName() {
  var className = [];
  var args = arguments[0];
  var type = Object.prototype.toString.call(args).slice(8, -1).toLowerCase();

  if (type === 'string') {
    args = args.trim();
    args && className.push(args);
  } else if (type === 'array') {
    args.forEach(function (cls) {
      cls = _getClassName(cls).trim();
      cls && className.push(cls);
    });
  } else if (type === 'object') {
    for (var k in args) {
      k = k.trim();

      if (k && args.hasOwnProperty(k) && args[k]) {
        className.push(k);
      }
    }
  }

  return className.join(' ').trim();
}

function _getStyle(classNameExpression) {
  var className = _getClassName(classNameExpression);

  var classNameArr = className.split(/\s+/);
  var style = [];

  if (classNameArr.length === 1) {
    style.push(_styleSheet[classNameArr[0].trim()]);
  } else {
    classNameArr.forEach(function (cls) {
      style.push(_styleSheet[cls.trim()]);
    });
  }

  return style;
}

let Company = class Company extends Component {
  constructor(props) {
    super(props);
    this.state = {
      cashType: 1,
      items: [1],
      totalCount: 0,
      pageIndex: 1,
      pageSize
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '查看明细' });
    this.getUserCommisions();
    // this.getUserCashes()
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  // 获取用户收益明细
  getUserCommisions() {
    let { userStore } = this.props.stores;
    let { pageIndex, pageSize } = this.state;
    userStore.getUserCommisions({
      pageIndex,
      pageSize,
      callback: res => {
        if (pageIndex === 1) {
          this.setState({ totalCount: toJS(res.totalCount), items: toJS(res.items) });
        } else {
          const { items } = this.state;
          items.push(...(res.items || []));
          this.setState({ totalCount: res.totalCount, items });
        }
      }
    });
  }
  // 获取用户提现明细
  getUserCashes() {
    let { userStore } = this.props.stores;
    let { pageIndex, pageSize } = this.state;
    userStore.getUserCashes({
      pageIndex,
      pageSize,
      callback: res => {
        if (pageIndex === 1) {
          this.setState({ totalCount: toJS(res.totalCount), items: toJS(res.items) });
        } else {
          const { items } = this.state;
          items.push(...(res.items || []));
          this.setState({ totalCount: res.totalCount, items });
        }
      }
    });
  }
  changeNav(id) {
    this.setState({
      cashType: id,
      totalCount: 0,
      items: []
    }, () => {
      if (id === 1) {
        this.getUserCommisions();
      } else {
        this.getUserCashes();
      }
    });
  }
  onReachBottom() {
    let { totalCount, pageSize, pageIndex } = this.state;
    const { loading } = this.props.stores.homeStore;
    if (totalCount > pageIndex * pageSize && !loading) {
      this.setState({
        pageIndex: pageIndex + 1
      }, () => {
        if (this.state.cashType === 1) {
          this.getUserCommisions();
        } else {
          this.getUserCashes();
        }
      });
    }
  }
  render() {
    let { cashType, items } = this.state;
    console.log(items);
    return <View style={[_styleSheet["my-my_profit"], _styleSheet["my-my_profit_cash_none"]]}>
        <ScrollView scrollX={true} style={_styleSheet["scroll-view-nav"]}>
          <View onClick={this.changeNav.bind(this, 1)} style={_getStyle(cashType === 1 ? 'scroll-item scroll-item-on' : 'scroll-item')}>
            收益明细
            <Text style={_styleSheet["line"]} />
          </View>
          <View onClick={this.changeNav.bind(this, 2)} style={_getStyle(cashType === 2 ? 'scroll-item scroll-item-on' : 'scroll-item')}>
            提现明细<Text style={_styleSheet["line"]} />
            <Text style={_styleSheet["line"]} />
          </View>
        </ScrollView>

        {cashType === 1 && <View>
            {items.length > 0 && <View>
                 <View style={_styleSheet["all-profit"]}>
                    累计收益： ￥6666666
                 </View>
                {items.map(item => {
            return <View style={_styleSheet["list-18-item"]}>
                      <Image src={getAvatar(item.avatar)} style={_styleSheet["img"]} />
                      <View style={_styleSheet["r"]}>
                        <View style={[_styleSheet["line"], _styleSheet["line1"]]}>
                          <View style={_styleSheet["list-title"]}>{item.name}
                          </View>
                          <View style={_styleSheet["list-info"]}>{subtime(item.creationTime)}</View>
                        </View>
                        <View style={[_styleSheet["line"], _styleSheet["line2"]]}>
                          <View style={[_styleSheet["list-title"], _styleSheet["add-cash"]]}>+{item.amount}</View>
                        </View>
                      </View>
                    </View>;
          })}
              </View>}
            {items.length <= 0 && <View>
                 <View style={_styleSheet["none-info"]}>
                    <Image src={noce_record} style={_styleSheet["none-icon"]} />
                    <Text style={[_styleSheet["none-title"], _styleSheet["list-desc"]]}>暂时还没有收益哦~</Text>
                 </View>
              </View>}
          </View>}
        {cashType === 2 && <View>
            {items.length > 0 && <View>
               <View style={_styleSheet["all-profit"]}>
                  累计收益： ￥6666666
               </View>
              {items.map(item => {
            return <View style={_styleSheet["list-18-item"]}>
                      <Image src={lawyer_pic} style={_styleSheet["img"]} />
                      <View style={_styleSheet["r"]}>
                        <View style={[_styleSheet["line"], _styleSheet["line1"]]}>
                          <View style={_styleSheet["list-title"]}>{item.name}
                          </View>
                          <View style={_styleSheet["list-info"]}>{subtime(item.creationTime)}</View>
                        </View>
                        <View style={[_styleSheet["line"], _styleSheet["line2"], _styleSheet["line-cash"]]}>
                          <View style={_styleSheet["list-title"]}>-{item.amount}</View>
                          <View style={[_styleSheet["type"], _styleSheet["cashing"]]}>提现中</View>
                        </View>
                      </View>
                    </View>;
          })}

               <View style={_styleSheet["list-18-item"]}>
                  <Image src={lawyer_pic} style={_styleSheet["img"]} />
                  <View style={_styleSheet["r"]}>
                     <View style={[_styleSheet["line"], _styleSheet["line1"]]}>
                        <View style={_styleSheet["list-title"]}>罗东
                        </View>
                        <View style={_styleSheet["list-info"]}>2019-12-5 12:12:12</View>
                     </View>
                     <View style={[_styleSheet["line"], _styleSheet["line2"], _styleSheet["line-cash"]]}>
                        <View style={_styleSheet["list-title"]}>-50.00</View>
                        <View style={[_styleSheet["type"], _styleSheet["success"]]}>提现成功</View>
                     </View>
                  </View>
               </View>

               <View style={_styleSheet["list-18-item"]}>
                  <Image src={lawyer_pic} style={_styleSheet["img"]} />
                  <View style={_styleSheet["r"]}>
                     <View style={[_styleSheet["line"], _styleSheet["line1"]]}>
                        <View style={_styleSheet["list-title"]}>罗东
                        </View>
                        <View style={_styleSheet["list-info"]}>2019-12-5 12:12:12</View>
                     </View>
                     <View style={[_styleSheet["line"], _styleSheet["line2"], _styleSheet["line-cash"]]}>
                        <View style={_styleSheet["list-title"]}>-50.00</View>
                        <View style={[_styleSheet["type"], _styleSheet["warn"]]}>提箱失败：恶意操作</View>
                     </View>
                  </View>
               </View>
            </View>}
            {items.length <= 0 && <View>
                 <View style={_styleSheet["none-info"]}>
                    <Image src={noce_record} style={_styleSheet["none-icon"]} />
                    <Text style={[_styleSheet["none-title"], _styleSheet["list-desc"]]}>暂时还没有提现记录哦~</Text>
                 </View>
              </View>}
          </View>}
      </View>;
  }
};
Company = tslib_1.__decorate([inject("stores"), observer], Company);
export default Company;